"""
Case Type   : USTORE
Case Name   : 验证参数max_undo_workers的异常值
Create At   : 2025/3/10
Owner       : wan005
Description :
    1.查询参数默认值
    2.修改参数值为0，
    3.修改参数值为101
    4.修改参数值为abc
Expect      :
    1.参数默认值为5
    2.修改失败
    3.修改失败
    4.修改失败
History     :
"""
import os
import unittest
import sys
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()

    def test_ustore(self):
        text = '-----step1:查询参数默认值;expect:参数默认值5-----'
        self.logger.info(text)
        res1 = self.common.show_param('max_undo_workers')
        self.assertEqual('5', res1, text + '执行失败')

        text = '-----step2:修改参数值为0;expect:失败-----'
        self.logger.info(text)
        err_msg2 = 'ERROR: The value 0 is outside the valid range for ' \
                  'parameter "max_undo_workers" (1 .. 100)'
        res2 = self.sh_primy.execute_gsguc('reload', err_msg2,
                                        'max_undo_workers=0')
        self.assertEqual(True, res2, text + '执行失败')

        text = '-----step3:修改参数值为101;expect:失败-----'
        self.logger.info(text)
        err_msg3 = 'ERROR: The value 101 is outside the valid range for ' \
                  'parameter "max_undo_workers" (1 .. 100)'
        res3 = self.sh_primy.execute_gsguc('reload', err_msg3,
                                        'max_undo_workers=101')
        self.assertEqual(True, res3, text + '执行失败')

        text = '-----step4:修改参数值为abc;expect:失败-----'
        self.logger.info(text)
        err_msg4 = 'The parameter "max_undo_workers" requires an integer value'
        res4 = self.sh_primy.execute_gsguc('reload', err_msg4,
                                      'max_undo_workers=abc')
        self.assertEqual(True, res4, text + '执行失败')

    def tearDown(self):
        self.logger.info(f'---{os.path.basename(__file__)} end---')
